package ${pack}.${module}.controller;

import com.syyo.admin.common.anno.SysLog;
import com.syyo.admin.domain.ResultVo;
import com.syyo.admin.utils.R;
import ${pack}.${module}.domain.req.${className}Req;
import ${pack}.${module}.service.${className}Service;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * @author: ${author}
 * @date: ${date}
 */
@Api(tags = "系统：${apiName}管理")
@RestController
@RequestMapping("/${lowerClassName}")
public class ${className}Controller {

    @Autowired
    private ${className}Service ${lowerClassName}Service;

     /**
      * ${apiName}新增
      * @param
      * @return
      */
    @SysLog("${apiName}新增")
    @ApiOperation("${apiName}新增")
    @PreAuthorize("@syyo.check('system:${lowerClassName}:add')")
    @PostMapping
    public ResultVo add(@RequestBody ${className}Req req) {
        return R.ok(${lowerClassName}Service.add(req));
    }

     /**
      * ${apiName}删除
      * @param
      * @return
      */
    @SysLog("${apiName}删除")
    @ApiOperation("${apiName}删除")
    @PreAuthorize("@syyo.check('system:${lowerClassName}:del')")
    @DeleteMapping
    public ResultVo del(@RequestBody ${className}Req req) {
        return R.ok(${lowerClassName}Service.del(req));
    }

    /**
      * ${apiName}编辑
      * @param req
      * @return
      */
    @SysLog("${apiName}编辑")
    @ApiOperation("${apiName}编辑")
    @PreAuthorize("@syyo.check('system:${lowerClassName}:edit')")
    @PutMapping
    public ResultVo edit(@RequestBody ${className}Req req) {
        return R.ok(${lowerClassName}Service.edit(req));
    }

    /**
      * ${apiName}详情
      * @param
      * @return
      */
    @ApiOperation("${apiName}详情")
    @GetMapping("/{id}")
    public ResultVo findOne(@PathVariable("id") Integer id) {
        return R.ok(${lowerClassName}Service.findOne(id));
    }

    /**
      * ${apiName}列表
      * @param
      * @return
      */
    @ApiOperation("${apiName}列表")
    @GetMapping("/list/{pageNum}/{pageSize}")
    public ResultVo findPage(@PathVariable("pageNum") Integer pageNum,
                            @PathVariable("pageSize") Integer pageSize,
                            ${className}Req req) {
        return R.ok(${lowerClassName}Service.findPage(pageNum, pageSize, req));
    }

    /**
     * ${apiName}导出
     * @param
     * @return
     */
    @SysLog("${apiName}导出")
    @ApiOperation("${apiName}导出")
    @PreAuthorize("@syyo.check('system:${lowerClassName}:export')")
    @PostMapping("/export")
    public void findPage(HttpServletResponse response) {
        ${lowerClassName}Service.export(response);
    }
}